package com.bjtu.laorenyouhao.guanliyuan.service.impl;

import com.bjtu.laorenyouhao.guanliyuan.feign.YigongFeignService;
import com.bjtu.laorenyouhao.guanliyuan.utils.RenyuanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjtu.common.utils.PageUtils;
import com.bjtu.common.utils.Query;

import com.bjtu.laorenyouhao.guanliyuan.dao.LaifangInfoDao;
import com.bjtu.laorenyouhao.guanliyuan.entity.LaifangInfoEntity;
import com.bjtu.laorenyouhao.guanliyuan.service.LaifangInfoService;
import org.springframework.util.StringUtils;


@Service("laifangInfoService")
public class LaifangInfoServiceImpl extends ServiceImpl<LaifangInfoDao, LaifangInfoEntity> implements LaifangInfoService {

    @Autowired
    private YigongFeignService yigongFeignService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        String key = (String) params.get("key");
        QueryWrapper<LaifangInfoEntity> queryWrapper = new QueryWrapper<LaifangInfoEntity>();
        if (StringUtils.hasLength(key)){
            queryWrapper.eq("id",key)
                    .or().like("begin_time",key)
                    .or().eq("people_id", RenyuanUtils.getYigongId(key,yigongFeignService));
        }

        IPage<LaifangInfoEntity> page = this.page(
                new Query<LaifangInfoEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}